# encoding=utf-8

BoolOp_TPL = """
// {comment}
func {function_name}(a *model.Expr, b *model.Expr) bool {{
	if a == nil || b == nil {{
		return false
	}}
	if a.ExprType != b.ExprType {{
		return false
	}}
	switch a.ExprType {{
	case model.ExprTypeInt64:
		return a.IntValue {operator} b.IntValue
	case model.ExprTypeStr:
		return a.StrValue {operator} b.StrValue
	case model.ExprTypeFloat:
		return a.FloatValue {operator} b.FloatValue
	}}
	return false
}}
"""

HEADER = """// Code generated from gen_op.py DO NOT EDIT.
package expression

import "mini-sql/model"
"""

def main():
	operator_code = HEADER
	operator_code += BoolOp_TPL.format(function_name = "BoolOpEQ", operator = "==", comment="等于")
	operator_code += BoolOp_TPL.format(function_name = "BoolOpNotEQ", operator = "!=", comment = "不等于,不能简单的对EQ函数结果取反")
	operator_code += BoolOp_TPL.format(function_name = "BoolOpGT", operator = ">", comment = "大于")
	operator_code += BoolOp_TPL.format(function_name = "BoolOpGTEQ", operator = ">=", comment = "大于等于")
	operator_code += BoolOp_TPL.format(function_name = "BoolOpLT", operator = "<", comment = "小于")
	operator_code += BoolOp_TPL.format(function_name = "BoolOpLTEQ", operator = "<=", comment = "小于")

	with open("expression/operator.gen.go", mode="w+", encoding="utf-8") as fp:
		fp.write(operator_code)

if __name__ == "__main__":
	main()
